package com.onlyphoto.onlymall.mvp.view.binder

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.mvp.view.activity.OrderConfirmActivity
import com.onlyphoto.onlymall.mvp.view.activity.ShippingAddressActivity

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-08-27.
 */
class OrderConfirmHeaderBinder : ItemViewBinder<String, OrderConfirmHeaderBinder.ViewHolder>() {


    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.order_confirm_header, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, address: String) {
        viewHolder.update(address)
        viewHolder.address?.setOnClickListener{
            (viewHolder.address?.context as OrderConfirmActivity).startActivityForResult(
                    Intent(viewHolder.address?.context, ShippingAddressActivity::class.java).putExtra("canBack", true), OrderConfirmActivity.REQUEST_ADDRESS)

        }
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var address: TextView? = null

        init {
            address = itemView.findViewById(R.id.address)
        }

        fun update(addr: String) {
            address?.text = addr
        }
    }
}
